package org.stone.project.common.utils;

import java.util.Date;

/**
 * 线程时间快照
 */
public class ThreadTimeSnap {
    private static ThreadLocal<Date> threadTimeHolder = new ThreadLocal<>();

    /**
     * 获取记录时间
     * @return
     */
    public static Date getRecordTime(){
        Date localDateTime = threadTimeHolder.get();
        if (localDateTime == null) {
            Date now = new Date();
            threadTimeHolder.set(now);
            return now;
        }
        return localDateTime;
    }

    /**
     * 时间清空
     * @return
     */
    public static void clear(){
        threadTimeHolder.remove();
    }
}
